<script setup lang="ts">
import { ref, onMounted } from "vue";
import { Api } from "../../assets/api/api";

//男生畅销榜
const bestSellerData = ref<Array<Object>>([]);
// 男生潜力榜
const potentialData = ref<Array<Object>>([]);
// 男生连载榜
const serialsData = ref<Array<Object>>([]);
// 男生完本榜
const finishData = ref<Array<Object>>([]);
//女生畅销榜
const girlBestSellerData = ref<Array<Object>>([]);
// 女生潜力榜
const girlPotentialData = ref<Array<Object>>([]);
// 女生连载榜
const girlSerialsData = ref<Array<Object>>([]);
// 女生完本榜
const girlFinishData = ref<Array<Object>>([]);

// 请求主要数据
const getMainData = async () => {
  let { data } = await Api.requestHomeRankingData();
  let MainData = data.data.list;
  // 男生畅销榜
  bestSellerData.value = MainData[2].list;
  // 男生潜力榜
  potentialData.value = MainData[3].list;
  // 男生连载榜
  serialsData.value = MainData[4].list;
  // 男生完本榜
  finishData.value = MainData[5].list;
  // 女生畅销榜
  girlBestSellerData.value = MainData[6].list;
  // 女生潜力榜
  girlPotentialData.value = MainData[7].list;
  // 女生连载榜
  girlSerialsData.value = MainData[3].list;
  // 女生完本榜
  girlFinishData.value = MainData[4].list;
};

onMounted(() => {
  getMainData();
});
</script>

<template>
  <div class="ranking_view">
    <h1 class="title">
      <van-image width="10" height="16" src="/img/home/boy.png" />
      男生榜
    </h1>
    <!-- 男生畅销榜 -->
    <div class="boy_free_sale">
      <div class="classification">
        <h1 class="bestsellers">
          男生畅销榜
          <van-image width="7" height="11" src="/img/home/right.png" />
        </h1>
        <ul>
          <li v-for="(item, index) in bestSellerData" :key="item.id">
            <div class="serial" style="background-color: #ff3333">
              {{ index + 1 }}
            </div>
            <p>
              <span v-if="item.category">[{{ item.category }}]</span
              >{{ item.title }}
            </p>
          </li>
        </ul>
      </div>
    </div>
    <!-- 男生潜力榜 -->
    <div class="boy_potential">
      <h1 class="bestsellers">
        男生潜力榜
        <van-image width="7" height="11" src="/img/home/right.png" />
      </h1>
      <ul class="boy_potential_ul">
        <li
          class="boy_potential_li"
          v-for="item in potentialData"
          :key="item.id"
        >
          {{ item.title }}
        </li>
      </ul>
    </div>
    <!-- 男生连载榜 -->
    <div class="boy_potential">
      <h1 class="bestsellers">
        男生连载榜
        <van-image width="7" height="11" src="/img/home/right.png" />
      </h1>
      <ul class="boy_potential_ul">
        <li
          class="boy_potential_li"
          v-for="item in serialsData"
          :key="item.id"
        >
          {{ item.title }}
        </li>
      </ul>
    </div>
    <!-- 男生完本榜 -->
    <div class="boy_potential">
      <h1 class="bestsellers">
        男生完本榜
        <van-image width="7" height="11" src="/img/home/right.png" />
      </h1>
      <ul class="boy_potential_ul">
        <li class="boy_potential_li" v-for="item in finishData" :key="item.id">
          {{ item.title }}
        </li>
      </ul>
    </div>
    <h1 class="title girl">
      <van-image width="10" height="16" src="/img/home/girl.png" />女生榜
    </h1>
    <!-- 女生畅销榜 -->
    <div class="boy_free_sale">
      <div class="classification">
        <h1 class="bestsellers">
          女生畅销榜
          <van-image width="7" height="11" src="/img/home/right.png" />
        </h1>
        <ul>
          <li v-for="(item, index) in girlBestSellerData" :key="item.id">
            <div class="serial" style="background-color: #ff3333">
              {{ index + 1 }}
            </div>
            <p>
              <span v-if="item.category">[{{ item.category }}]</span
              >{{ item.title }}
            </p>
          </li>
        </ul>
      </div>
    </div>
    <!-- 女生潜力榜 -->
    <div class="boy_potential">
      <h1 class="bestsellers">
        女生潜力榜
        <van-image width="7" height="11" src="/img/home/right.png" />
      </h1>
      <ul class="boy_potential_ul">
        <li
          class="boy_potential_li"
          v-for="item in girlPotentialData"
          :key="item.id"
        >
          {{ item.title }}
        </li>
      </ul>
    </div>
    <!-- 女生连载榜 -->
    <div class="boy_potential">
      <h1 class="bestsellers">
        女生连载榜
        <van-image width="7" height="11" src="/img/home/right.png" />
      </h1>
      <ul class="boy_potential_ul">
        <li
          class="boy_potential_li"
          v-for="item in girlSerialsData"
          :key="item.id"
        >
          {{ item.title }}
        </li>
      </ul>
    </div>
    <!-- 女生完本榜 -->
    <div class="boy_potential con">
      <h1 class="bestsellers">
        女生完本榜
        <van-image width="7" height="11" src="/img/home/right.png" />
      </h1>
      <ul class="boy_potential_ul">
        <li
          class="boy_potential_li"
          v-for="item in girlFinishData"
          :key="item.id"
        >
          {{ item.title }}
        </li>
      </ul>
    </div>
  </div>
</template>

<style lang="scss" scoped>
.title {
  height: 35px;
  background-color: #60c7e4;
  font-weight: normal;
  color: #fff;
  margin-top: 6px;
  font-size: 16px;
  display: flex;
  justify-content: center;
  align-items: center;
  &.girl {
    margin-top: 0;
    background-color: #ff7a8d;
  }
}
.classification {
  margin-bottom: 10px;
  margin-top: 0;
  & > h1 {
    height: 38px;
    font-size: 16px;
    color: #5f5f5f;
    outline: 1px solid #eeeeee;
    background-color: #fff;
    display: flex;
    & > span {
      display: inline-block;
      width: 33%;
      height: 36px;
      line-height: 36px;
      text-align: center;
      font-size: 16px;
      color: #5f5f5f;
      font-weight: normal;
      &.con {
        border-bottom: 2px solid #f2503c;
      }
    }
  }
  ul {
    padding: 0 10px;
    background-color: #fff;
  }
  li {
    height: 42px;
    display: flex;
    align-items: center;
    border-bottom: 1px solid #efefef;
    .serial {
      width: 15px;
      height: 15px;
      text-align: center;
      line-height: 15px;
      border-radius: 2px;
      color: #fff;
      font-size: 13px;
      margin-right: 10px;
    }
    p {
      font-size: 15px;
      color: #333333;
      span {
        color: #666666;
        display: inline-block;
        margin-right: 6px;
      }
    }
  }
  h2 {
    height: 44px;
    line-height: 44px;
    text-align: center;
    font-size: 14px;
    color: #333333;
    font-weight: normal;
    background-color: #fff;
    margin-bottom: 20px;
    & > span {
      display: inline-block;
      width: 5px;
      height: 10px;
      background: url("/public/img/home/right.png");
      background-size: cover;
    }
  }
}
.bestsellers {
  height: 38px;
  font-size: 16px;
  color: #5f5f5f;
  outline: 1px solid #eeeeee;
  background-color: #fff;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding-right: 10px;
  padding-left: 10px;
  font-weight: normal;
}
.boy_potential {
  margin-top: 10px;
  &.con {
    margin-bottom: 20px;
  }
  .boy_potential_ul {
    display: flex;
    flex-wrap: wrap;
    background-color: #fff;
    padding: 15px 10px 5px;
  }
  .boy_potential_li {
    height: 32px;
    padding: 0 10px;
    border: 1px solid #d2d6d8;
    background-color: #f3f3f3;
    text-align: center;
    line-height: 32px;
    font-size: 14px;
    color: #333;
    margin-right: 10px;
    margin-bottom: 10px;
  }
}
</style>